home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_d / rtdc.zip / TESTUNI2.PAS < prev   
Pascal/Delphi Source File  |  1995-09-03  |  4KB  |  155 lines

  1. unit Testuni2;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, RtDbCopy, DBTables, DB, ExtCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Panel1: TPanel;
  12.     Label1: TLabel;
  13.     ComboBox1: TComboBox;
  14.     Label2: TLabel;
  15.     Edit1: TEdit;
  16.     Database1: TDatabase;
  17.     Table1: TTable;
  18.     Table2: TTable;
  19.     BatchMove1: TBatchMove;
  20.     RtDbCopy1: TRtDbCopy;
  21.     Button1: TButton;
  22.     Button2: TButton;
  23.     Label3: TLabel;
  24.     Label4: TLabel;
  25.     Bevel1: TBevel;
  26.     Label7: TLabel;
  27.     Label8: TLabel;
  28.     CheckBox1: TCheckBox;
  29.     RadioGroup1: TRadioGroup;
  30.     procedure ComboBox1Change(Sender: TObject);
  31.     procedure Edit1Change(Sender: TObject);
  32.     procedure Button1Click(Sender: TObject);
  33.     procedure Button2Click(Sender: TObject);
  34.     procedure FormCreate(Sender: TObject);
  35.   private
  36.     { Private-Deklarationen }
  37.   public
  38.     { Public-Deklarationen }
  39.   end;
  40.  
  41. var
  42.   Form1: TForm1;
  43.  
  44. implementation
  45.  
  46. uses
  47.     Login;
  48.  
  49. {$R *.DFM}
  50.  
  51. procedure TForm1.ComboBox1Change(Sender: TObject);
  52. begin
  53.     if Table1.Active then
  54.        Table1.Close;
  55. {   Table1.TableName := ComboBox1.Items[ComboBox1.ItemIndex];}
  56.    Table1.TableName := ComboBox1.Text
  57. end;
  58.  
  59. procedure TForm1.Edit1Change(Sender: TObject);
  60. begin
  61.     if Table2.Active then
  62.        Table2.Close;
  63.    Table2.TableName := Edit1.Text;
  64. end;
  65.  
  66. procedure TForm1.Button1Click(Sender: TObject);
  67. var
  68.     T: TDateTime;
  69.    n: integer;
  70. begin
  71.     Button1.Enabled := False;
  72.    try
  73.        Table1.Open;
  74.       BatchMove1.Mappings.Clear;
  75.       if CheckBox1.Checked then
  76.           for n:=Table1.FieldDefs.Count-1 downto 0 do
  77.              if (n mod 2)=0 then
  78.                  BatchMove1.Mappings.Add(Table1.FieldDefs[n].Name+'='+Table1.FieldDefs[n].Name);
  79.        Label8.Caption := IntToStr(Table1.RecordCount);
  80.       BatchMove1.Mode := TBatchMode(RadioGroup1.ItemIndex);
  81.        Label3.Caption := '00:00:00';
  82.        T := Time;
  83.        BatchMove1.Execute;
  84.        Label3.Caption := FormatDateTime('hh:nn:ss',Time-T);
  85.    finally
  86.        Button1.Enabled := True;
  87.    end;
  88. end;
  89.  
  90. procedure TForm1.Button2Click(Sender: TObject);
  91. var
  92.     T: TDateTime;
  93.    n: integer;
  94. begin
  95.     Button2.Enabled := False;
  96.    try
  97.        Table1.Open;
  98.       RtDbCopy1.Mappings.Clear;
  99.       if CheckBox1.Checked then
  100.           for n:=Table1.FieldDefs.Count-1 downto 0 do
  101.              if (n mod 2)=0 then
  102.                  RtDbCopy1.Mappings.Add(Table1.FieldDefs[n].Name+'='+Table1.FieldDefs[n].Name);
  103.        Label8.Caption := IntToStr(Table1.RecordCount);
  104.       RtDbCopy1.Mode := TRtCopyMode(RadioGroup1.ItemIndex);
  105.        Label4.Caption := '00:00:00';
  106.        T := Time;
  107.        RtDbCopy1.Execute;
  108.        Label4.Caption := FormatDateTime('hh:nn:ss',Time-T);
  109.    finally
  110.        Button2.Enabled := True;
  111.    end;
  112. end;
  113.  
  114. function SqlLogin(Database: TDatabase; AliasName,UserName,Password: string): Boolean;
  115. begin
  116.    if Database.Connected then
  117.       Database.Close;
  118.    Database.AliasName := AliasName;
  119.    Database.Params.Values['USER NAME'] := UserName;
  120.    Database.Params.Values['PASSWORD'] := Password;
  121.    Database.Open;
  122.    Result := Database.Connected;
  123. end;
  124.  
  125. procedure TForm1.FormCreate(Sender: TObject);
  126. var
  127.     List: TStringList;
  128. begin
  129.    if not Database1.Connected then
  130.    begin
  131.       LoginForm := TLoginForm.Create(Application);
  132.       try
  133.          if LoginForm.ShowModal=idOK then
  134.             try
  135.                SqlLogin(Database1,LoginForm.Alias,LoginForm.User,LoginForm.Password);
  136.             except
  137.                if (not Database1.Connected) then
  138.                   raise EDatabaseError.Create('Login fehlgeschlagen !');
  139.             end;
  140.       finally
  141.          LoginForm.Release;
  142.       end;
  143.    end;
  144.    if Database1.Connected then
  145.    begin
  146.        List := TStringList.Create;
  147.        Session.GetTableNames(Database1.DatabaseName,'',True,False,List);
  148.       ComboBox1.Items.Assign(List);
  149.       List.Free;
  150.    end;
  151.    RadioGroup1.ItemIndex := integer(batCopy);
  152. end;
  153.  
  154. end.
  155.